#!/usr/bin/env python3.9
# -*- encoding: utf-8 -*-
"""
@文件        :models.py
@说明        : 证件照相关配置模型
@时间        :2022/11/29 15:55:53
@作者        :Mars
@版本        :1.0
"""
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models

from mars.utils.models import BaseModel


# Create your models here.
class Background(BaseModel):
    """证件照底色背景模型,
    定义证件照背景的颜色包含:
        1.纯色背景(红\蓝\白\灰色)
        2.上下方向渐变色(主色和次色)
    """

    name = models.CharField(
        max_length=18, unique=True, verbose_name="背景名称", help_text="背景名称"
    )
    primary_color = models.CharField(
        max_length=7, verbose_name="主背景颜色", help_text="主背景颜色"
    )
    secondary_color = models.CharField(
        max_length=7, null=True, blank=True, verbose_name="次背景色"
    )

    class Meta:
        db_table = "tb_photo_bg"
        verbose_name = "背景颜色"
        verbose_name_plural = verbose_name


class Category(BaseModel):
    """证件照类型模型
    如:教育\考试\国考等
    """

    name = models.CharField(max_length=20, verbose_name="类型名称", help_text="类型名称")
    desc = models.TextField(
        max_length=30, null=True, blank=True, verbose_name="描述", help_text="描述"
    )
    # *图片被删除后,字段设为null;db_constraint=False,保留跨表查询的便利(双下划线跨表查询```)
    # icon = models.ForeignKey(GalleryModel,null=True,on_delete=models.SET_NULL, db_constraint=False,help_text="类型图标")

    def __str__(self) -> str:
        return self.name

    class Meta:
        db_table = "tb_photo_category"
        verbose_name = "类型"
        verbose_name_plural = verbose_name

        

class IDPhoto(BaseModel):
    """证件照尺寸模型:
        如:一寸 两寸 身份证照片 驾驶证照片
    """

    name = models.CharField(max_length=30, verbose_name="尺寸名称")
    width = models.SmallIntegerField(default=0, verbose_name="宽度(mm)")
    height = models.SmallIntegerField(default=0, verbose_name="高度(mm)")
    top_dis = models.SmallIntegerField(default=2, verbose_name="头顶与上边缘距离")
    edge_dis = models.SmallIntegerField(default=5, verbose_name="双耳与左右边距")
    dpi = models.SmallIntegerField(
        default=300,
        validators=[MinValueValidator(72), MaxValueValidator(350)],
        verbose_name="证件照分辨率",
    )
    # 证件照为True,普通照片为False
    is_idphoto = models.BooleanField(default=True, verbose_name="证件照")
    is_common = models.BooleanField(default=False, verbose_name="常用")
    category = models.ForeignKey(Category, related_name="photos", on_delete=models.CASCADE,verbose_name="类型")

    class Meta:
        db_table = "tb_idphoto"
        verbose_name = "尺寸"
        verbose_name_plural = verbose_name

    